package ecstore.client.customWidgets;

import java.util.Iterator;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;

import ecstore.client.DataStorageService;
import ecstore.client.DataStorageServiceAsync;
import ecstore.client.dataOperation.ItemInfo;


public class TobaccoPanel extends Composite {

	FlexTable flexTable = new FlexTable();
	int numRow = 2;
	int numCol = 2;
	
	
	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final DataStorageServiceAsync dataStorageService = GWT.create(DataStorageService.class);
	
	public TobaccoPanel(){
		
		flexTable.setCellSpacing(5);
		flexTable.setCellPadding(3);
		flexTable.setSize("384px", "306px");

		initWidget(flexTable);
		
		
		dataStorageService.getTobacco(new AsyncCallback<List<ItemInfo>>() {

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				System.out.println("faild to rechieve the item info");
			}

			public void onSuccess(List<ItemInfo> result) {
				
				Iterator<ItemInfo> itr = result.iterator();
				ItemInfo itemInfo = new ItemInfo();
				while(itr.hasNext()){
					itemInfo = (ItemInfo) itr.next();
					ItemSlot itemSlot = new ItemSlot(itemInfo);
					
					
					
//					itemSlot.setImage(itemInfo.getThumbnail());
//					itemSlot.setPrice(itemInfo.getPrice());
//					itemSlot.setName(itemInfo.getName());
					
					flexTable.setWidget(itemInfo.getRowNum(), itemInfo.getColNum(), itemSlot);
				}
				
			}
			
		});
		/*
		ItemSlot itemSlot = new ItemSlot();
		flexTable.setWidget(0, 0, itemSlot);
		
		ItemSlot itemSlot_13 = new ItemSlot();
		flexTable.setWidget(0, 1, itemSlot_13);
		
		ItemSlot itemSlot_6 = new ItemSlot();
		flexTable.setWidget(0, 2, itemSlot_6);
		
		ItemSlot itemSlot_2 = new ItemSlot();
		flexTable.setWidget(1, 0, itemSlot_2);
		
		ItemSlot itemSlot_12 = new ItemSlot();
		flexTable.setWidget(1, 1, itemSlot_12);
		
		ItemSlot itemSlot_8 = new ItemSlot();
		flexTable.setWidget(1, 2, itemSlot_8);
		
		ItemSlot itemSlot_14 = new ItemSlot();
		flexTable.setWidget(2, 0, itemSlot_14);
		
		ItemSlot itemSlot_15 = new ItemSlot();
		flexTable.setWidget(3, 0, itemSlot_15);
		
		ItemSlot itemSlot_16 = new ItemSlot();
		flexTable.setWidget(4, 0, itemSlot_16);
		
		ItemSlot itemSlot_17 = new ItemSlot();
		flexTable.setWidget(4, 1, itemSlot_17);
		
		ItemSlot itemSlot_1 = new ItemSlot();
		flexTable.setWidget(5, 0, itemSlot_1);
		
		ItemSlot itemSlot_3 = new ItemSlot();
		flexTable.setWidget(6, 0, itemSlot_3);
		*/
	}
	
}
